<?php
require_once dirname(__FILE__) . '/taobao.class.php'; 
class taobao_oauth
{
    private $_need_request = array('code', 'state');

    public function __construct($setting) {
        //组装回调地址
		$this->redirect_uri = C('YTATA_SITE_DOMAIN').__ROOT__.RU('callback/oauth',array('mod'=>'taobao'));
        $this->setting = $setting;
    }
    /**
     * 获取授权地址
     */
    function getAuthorizeURL() {
        $oauth = new TaobaoTOAuthV2($this->setting['app_id'], $this->setting['app_key']);
        return $oauth->getAuthorizeURL($this->redirect_uri);
    }

    /**
     * 获取用户信息
     */
	public function getUserInfo($request_args) {
        $oauth = new TaobaoTOAuthV2($this->setting['app_id'], $this->setting['app_key'] );
        $keys = array('code'=>$request_args['code'], 'redirect_uri'=>$this->redirect_uri);
        $token = $oauth->getAccessToken($keys);
        $result['keyid'] = $token['taobao_user_id'];
        $result['keyname'] = $token['taobao_user_nick'];
 		$result['keyavatar_big'] = '';
        $result['keyavatar_small'] = '';
        $result['bind_info'] = $token;
       return $result;
    } 
    

    
    public function NeedRequest() {
        return $this->_need_request;
    }
}